package com.emergency.examine.dao;

import com.emergency.examine.domain.PaperQuestion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PaperQuestionDao extends JpaRepository<PaperQuestion, Long>, JpaSpecificationExecutor<PaperQuestion> {
    @Query("select pq from PaperQuestion pq where paper.id = :paperId")
    List<PaperQuestion> findAllByPaper(Long paperId);

    @Modifying
    @Transactional
    @Query(value = "delete FROM ex_paper_question WHERE paper_id = ? ", nativeQuery = true)
    void deleteByPaperId(Long paperId);
}
